package com.summer.JUnit;

public class MyStack {

	private String[] stack;
	private int next_index;
	
	public MyStack(){
		stack = new String[100];
		next_index = 0;
	}
	
	public String pop(){
		return stack[--next_index];
	}
	
	public void delete(int number){
		next_index -= number;
	}
	
	public void push(String aString){
		stack[next_index++] = aString;
	}
	
	public String top(){
		return stack[next_index-1];
	}
	
	public void checkInvariant() throws InvariantException{
		if(!(next_index >= 0 && next_index < stack.length)){
			throw new InvariantException("next_index out of range: "+ next_index + " for stack length "+stack.length);
		}
			
	}
	
	public class InvariantException extends Exception{
		private static final long serialVersionUID = 1L;

		public InvariantException(){
			super();
		}
		
		public InvariantException(String msg){
			super(msg);
		}
	}
}
